<?php
$aPosition = unserialize(ADVERTISE_POST_ARRAY);
$sOptionPosition = "";
foreach($aPosition as $key=>$ps) {
    $sOptionPosition .= "<option value='{$key}'>{$ps}</option>";
}
?>

<div class="row">
    <h1 class="col-md-6 col-xs-12">Quảng cáo</h1>
    <h1 class="col-md-6 col-xs-12">
        <a class="btn btn-default pull-right mgl5" href="<?php echo admin_page_url(ADVERTISE_SLUG); ?>">
            <i class="glyphicon glyphicon-share-alt"></i> Trở về
        </a>
        <button type="button" class="btn btn-success pull-right" onclick="wireOfAction('#btn-new', 'click');">
            <i class="glyphicon glyphicon-ok-sign"></i> <?php echo $action; ?>
        </button>
    </h1>
    <div class="col-md-12 col-xs-12">
      <ol class="breadcrumb">
        <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li><a href="<?php echo admin_page_url(ADVERTISE_SLUG); ?>"><i class="fa fa-dashboard"></i> Quảng cáo</a></li>
    </ol>
</div>
</div>

<div class='row'>
    <h1 class="col-md-12 col-xs-12">Thêm quảng cáo mới</h1>
    <form role="form" method="post" action="<?php echo $actionLink; ?>">
        <div class="col-md-6 col-xs-12">
            <div class="row">
                <div class="form-group col-xs-12 col-md-12">
                    <label for="input-advertise-anchor">Liên kết</label>
                    <input type="text" class="form-control" id="input-advertise-anchor" name="advertise[anchor]" value="<?php echo $advertiseInfo->getAnchor(); ?>" placeholder="http://www.example.com" />
                </div>

                <div class="form-group col-md-12 col-xs-12">
                    <label for="input-advertise-user">Người dùng</label>
                    <?php
                    $name = '';
                    $email = '';
                    if($advertiseInfo->getUserId()==''){
                        $opt_info = unserialize($advertiseInfo->getOptInfo());
                        $name = $opt_info['name'];
                        $email = $opt_info['email'];
                    } else {
                        foreach($aUser as $u){
                            if($u->getId() == $advertiseInfo->getUserId()){
                                $name = $u->getFullName();
                                $email = $u->getEmail();
                                break;
                            }
                        }
                    }
                    ?>

                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                        <input type="text" class="form-control" id="input-advertise-user" name="advertise[name]" value="<?php echo $name; ?>" />
                        <span class="input-group-btn">
                            <button class="btn btn-success" type="button" data-toggle="modal" data-target="#modal-user">
                                <i class="glyphicon glyphicon-search"></i>
                            </button>
                        </span>
                    </div><!-- /input-group -->
                </div>
                <div class="form-group col-md-12 col-xs-12">
                    <label for="input-advertise-email">Email</label>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
                        <input type="text" class="form-control" id="input-advertise-email" name="advertise[email]" value="<?php echo $email; ?>" />
                    </div>
                </div>
                <div class="form-group col-xs-9 col-md-9">
                    <label for="input-advertise-position">Vị trí</label>
                    <select class="form-control" id="input-advertise-position" name="advertise[position]">
                        <?php foreach($aPosition as $key=>$ps) { ?>
                        <option value="<?php echo $key; ?>" <?php echo $advertiseInfo->getPosition()==$key?"selected='selected'":""; ?> >
                            <?php echo $ps; ?>
                        </option>
                        <?php } ?>
                    </select>
                </div>
                <div class="form-group col-xs-3 col-md-3">
                    <label for="input-advertise-order">Thứ tự</label>
                    <input type="text" class="form-control" id="input-advertise-order" name="advertise[order]" value="<?php echo $advertiseInfo->getOrder(); ?>" />
                </div>
                <div class="form-group col-md-6 col-xs-6">
                    <label for="input-advertise-start-date-1">Ngày bắt đầu</label>
                    <input type="text" class="form-control input-date" id="input-advertise-start-date-1" name="advertise[start_date]" autocomplete="off" value="<?php echo $advertiseInfo->getStartDate(); ?>" />
                </div>
                <div class="form-group col-md-6 col-xs-6">
                    <label for="input-advertise-end-date-1">Ngày kết thúc</label>
                    <input type="text" class="form-control input-date" id="input-advertise-end-date-1" name="advertise[end_date]" autocomplete="off" value="<?php echo $advertiseInfo->getEndDate(); ?>" />
                </div>

                <div class="form-group col-md-12 col-xs-12">
                    <label for="input-advertise-content">Nội dung quảng cáo</label>
                    <textarea class="form-control mgt5" id="input-advertise-content" name="advertise[content]" rows="5"><?php echo $advertiseInfo->getContent(); ?></textarea>
                    <button type="button" class="btn btn-success pull-right mgt5" data-toggle="modal" data-target="#modal-image">
                        <i class="glyphicon glyphicon-picture"></i> Tải lên hình ảnh
                    </button>
                    <div class="clearfix"></div>
                </div>

                <div class="form-group col-md-12 col-xs-12">
                    <label for="input-advertise-publish-flg">
                        <input type="checkbox" id="input-advertise-publish-flg" name="advertise[publish_flg]" value="1" <?php echo $advertiseInfo->getPublishFlg()==1?'checked="checked"':''; ?> />
                        &nbsp;Hiển thị
                    </label>
                </div>

                <div class="form-group col-md-12 col-xs-12">
                    <?php if($action == 'Cập nhật') { ?>
                    <input type="hidden" name="case" value='<?php echo UPDATE_FULL; ?>' />
                    <input type="hidden" name="advertise[id]" value="<?php echo $this->encrypt->encode($advertiseInfo->getId()); ?>" />
                    <input type="hidden" id="input-advertise-user-id" name="advertise[user_id]" value="<?php echo  $this->encrypt->encode($advertiseInfo->getUserId()); ?>" />
                    <?php } else { ?>
                    <input type="hidden" id="input-advertise-user-id" name="advertise[user_id]" />
                    <?php } ?>
                    <button type="button" id="btn-new" class="btn btn-success btn-submit-update"><i class="glyphicon glyphicon-ok-sign"></i> <?php echo $action; ?></button>
                    <a class="btn btn-default" href="<?php echo admin_page_url(ADVERTISE_SLUG); ?>"><i class="glyphicon glyphicon-share-alt"></i> Trở về</a>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-xs-12">
            <a class="thumbnail" href="#" id="input-advertise-content-preview"><?php echo $advertiseInfo->getContent(); ?></a>
        </div>
    </form>
</div>

<div id="modal-user" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">Chọn người dùng</h4>
            </div>
            <div class="modal-body">
                <label>
                    <input type="radio" class="rad-user" name="ad-user-type" id="rad-sys-user" data-panel="#pn-sys-user" value="1" checked="checked" />
                    Người dùng trong hệ thống
                </label>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <label>
                    <input type="radio" class="rad-user" name="ad-user-type" id="rad-out-user" data-panel="#pn-out-user" value="0" />
                    Khách đăng kí
                </label>

                <div id="pn-sys-user" class="form-group pn-user mgt10">
                    <select class="form-control" id="input-advertise-temp-user">
                        <?php foreach($aUser as $user) { ?>
                        <option value="<?php echo $this->encrypt->encode($user->getId()); ?>"
                            data-email="<?php echo $user->getEmail(); ?>"
                            <?php echo $advertiseInfo->getUserId()==$user->getId()?"selected='selected'":""; ?> >
                            <?php echo $user->getFullName(); ?>
                        </option>
                        <?php } ?>
                    </select>
                </div>

                <div id="pn-out-user" class="pn-user hidden mgt10">
                    <div class="form-group">
                        <label for="input-advertise-temp-name">Tên</label>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                            <input type="text" class="form-control" id="input-advertise-temp-name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input-advertise-temp-email">Email</label>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
                            <input type="text" class="form-control" id="input-advertise-temp-email" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove-sign"></i> Thoát</button>
                <button type="button" class="btn btn-primary" id="btn-choose-user"><i class="glyphicon glyphicon-ok-sign"></i> Đồng ý</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php $this->load->view('backend/admin/image-modal/advertise.html.php'); ?>